package com.lightdz.tshirtdz.dal.impl;

import com.lightdz.tshirtdz.model.Enum.BaseStatusEnum;
import com.lightdz.tshirtdz.model.entity.FavoriteEntity;

import com.lightdz.tshirtdz.utils.MybatisDBHelper;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;

import java.util.Date;
import java.util.List;

/**
 * @ Description：${description}
 * @ Author     ：zbl
 * @ Date       ：Created in 16:54 09/08/2018
 * @ Modified By：
 */

@Repository
public class FavoriteDal implements Runnable{

    /**
     * 获取我的收藏列表
     *
     * @param wxId
     * @return
     */
    public List<FavoriteEntity> getFavoriteList(String wxId) {

        List<FavoriteEntity> favList =(List<FavoriteEntity>) MybatisDBHelper.SelectListById("getFavoriteList", wxId);
        return favList;
    }

    /**
     * 添加到我的收藏
     *
     * @param wxId
     * @param pid
     * @return
     */
    public boolean addFavorite(String wxId, long pid) {
        FavoriteEntity entity = new FavoriteEntity();
        Date date = new Date();
        entity.setCreatetime(new Timestamp(date.getTime()));
        entity.setPid((int) pid);
        entity.setStatus(BaseStatusEnum.Normal.getValue());
        entity.setWxid(wxId);
        int result = MybatisDBHelper.Add("addFavorite", entity);
        return result > 0;
    }

    public boolean deleteFavorite(String wxId, long pid) {
        FavoriteEntity entity = new FavoriteEntity();
        entity.setWxid(wxId);
        entity.setPid((int) pid);
        int result = MybatisDBHelper.Delete("deleteFavorite", entity);
        return result > 0;
    }

    @Override
    public void run() {

    }
}
